import Vue from 'vue'
import Router from 'vue-router'
// 引入多个动态路由模块
import approvalsRouter from './modules/approvalsRouter.js'
import departmentsRouter from './modules/departmentsRouter.js'
import employeesRouter from './modules/employeesRouter.js'
import permissionRouter from './modules/permissionRouter.js'
import attendancesRouter from './modules/attendancesRouter.js'
import salarysRouter from './modules/salarysRouter.js'
import settingRouter from './modules/settingRouter.js'
import socialRouter from './modules/socialRouter.js'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 动态路由
export const asyncRoutes = [
  departmentsRouter, // 部门管理
  settingRouter, // 角色管理
  employeesRouter, // 员工管理
  permissionRouter, // 权限管理
  approvalsRouter,
  attendancesRouter,
  salarysRouter,
  socialRouter
]

// 静态路由（不需要特殊的权限控制，就可以访问的页面）
export const constantRoutes = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "login" */'@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import(/* webpackChunkName: "404" */'@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import(/* webpackChunkName: "dashboard" */'@/views/dashboard/index'),
      meta: { title: '主页', icon: 'home' }
    }]
  },
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true },
  {
    path: '/import',
    component: Layout,
    hidden: true, // 不显示到左侧菜单
    children: [{
      path: '',
      component: () => import(/* webpackChunkName: "Layout" */'@/views/import')
    }]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 合并两个路由
  routes: [...constantRoutes]
})

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
